from typing import Optional

from pydantic import ConfigDict
from typing_extensions import Self

from app.utils.decorators.optional import optional
from ..models.api import BaseApi
from ..models.base import SQLBaseModel, IdType


class ApiCreate(BaseApi):
    parent_id: Optional[IdType] = None


@optional(without_fields=["id"])
class ApiUpdate(ApiCreate):
    id: IdType


class ApiOut(SQLBaseModel, BaseApi):
    model_config = ConfigDict(from_attributes=True)
    parent_id: IdType | None


class ApiTreeOut(SQLBaseModel, BaseApi):
    model_config = ConfigDict(from_attributes=True)

    parent_id: IdType | None
    children: list[Self] | None

class ApiExport(ApiOut):
    model_config = ConfigDict(from_attributes=True)
